using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using MoMing.VideoTool.Downloader.Extensions;
using MoMing.VideoTool.Downloader.Model;
using Npgsql;

namespace MoMing.VideoTool.Downloader.Infrastructure
{
    public partial class DonwloaderContextSeed(IWebHostEnvironment env,

    ILogger<DonwloaderContextSeed> logger) : IDbSeeder<DonwloaderContext>
    {
        public async Task SeedAsync(DonwloaderContext context)
        {
            context.Database.OpenConnection();
            ((NpgsqlConnection)context.Database.GetDbConnection()).ReloadTypes();

            if (!context.DownloadLogs.Any())
            {

                context.RemoveRange(context.DownloadLogs);
                var log = new DownloadLog("xfsdfsfsfsdfd","这是什么", "抖音", "http://localhost:15042/consolelogs/resource/videotool-downloader-b6dcn60", "c:\\download\\xfsdfsfsfsdfd.mp4");
                await context.DownloadLogs.AddAsync(log);
                await context.SaveChangesAsync();
                logger.LogInformation("Seed data successful.");
            }
        }
    }
}